<?php
/**
 * Marco Mounzer
 * m.mounzer@gmail.com
 * @copyright 2013
 */
function controllaEmail($email) {

    $email = strtolower(trim($email));

    //if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $this->email))

    if (!filter_var($email, FILTER_VALIDATE_EMAIL))
        return "Il campo email non è stato inserito correttamente";

    if (strlen($email) > 100)
        return "Il campo email non può superare i 100 caratteri";

    return true;
}

function sendEmail($to, $subject, $message, $reply = null) {
    //message
    //To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

    //Additional headers
    $headers .= 'To: ' . $to . "\r\n";
    $headers .= 'From: ' . $to . "\r\n";
    $headers .= 'Reply-To: ' . $reply . "\r\n";

    //Mail it
    return mail($to, $subject, $message, $headers);
}